<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\cassification\controller;

use plugin\saiadmin\basic\BaseController;
use app\cassification\logic\ClassificationDictionaryLogic;
use app\cassification\validate\ClassificationDictionaryValidate;
use support\Request;
use support\Response;

/**
 * 分类字典控制器
 */
class ClassificationDictionaryController extends BaseController
{
    /**
     * 数据表主键
     */
    protected $pk = 'dictionary_id';
    
    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->logic = new ClassificationDictionaryLogic();
        $this->validate = new ClassificationDictionaryValidate;
        parent::__construct();
    }

    /**
     * 数据列表
     * @param Request $request
     * @return Response
     */
    public function index(Request $request): Response
    {
        $where = $request->more([
            ['classification_type', ''],
            ['classification_name_zh', ''],
            ['classification_name_en', ''],
            ['classification_name_ja', ''],
            ['classification_name_ko', ''],
        ]);
        $query = $this->logic->search($where);
        $data = $this->logic->getList($query);
        return $this->success($data);
    }

    public  function  getCate(Request $request): Response
    {
        $classification_type = $request->input('classification_type', '');
        $result = $this->logic->where('classification_type', $classification_type)
        ->field('dictionary_id as value,classification_name_zh as label')
        ->order('dictionary_id desc')  // 增加排序保证结果一致性
        ->select()
        ->toArray();
        return $this->success($result,'获取成功');
       

    }

    public  function  getCateList(Request $request): Response
    {
        $dictionary_id = $request->input('dictionary_id', '');
        $dictionary_id=json_decode($dictionary_id);
        $result = $this->logic->whereIn('dictionary_id', $dictionary_id)
            ->field('classification_name_zh as value,classification_name_zh as label')
            ->order('dictionary_id desc')  // 增加排序保证结果一致性
            ->select()
            ->toArray();
        return $this->success($result,'获取成功');


    }

}
